﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplicationCultura.Clases;

namespace WebApplicationCultura.Pages.Eventos
{
    public partial class modificarevento1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            HttpCookie cookie = Request.Cookies["idEvento"];
            culturaDataContext cultura = new culturaDataContext();
            if (cookie != null)
            {

                var evento = from ev in cultura.EVENTOs where ev.ID_EVENTO == decimal.Parse(cookie.Value) select ev;
                this.TextBox1.Text = evento.First().NOMBRE_EVENTO;
                this.TextBox2.Text = evento.First().UBICACION_EVENTO;
                this.Calendar1.SelectedDate = evento.First().INICIO_EVENTO;
                this.TextBox3.Text = evento.First().INICIO_EVENTO.ToString();
                this.Calendar2.SelectedDate = evento.First().FIN_EVENTO;
                this.TextBox4.Text = evento.First().FIN_EVENTO.ToString();
                this.TextBox5.Text = evento.First().AUDIENCIA_EVENTO.ToString();
                this.TextBox6.Text = evento.First().DESCRIPCION_EVENTO;
            }
            else
            {
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                Response.Redirect("/Pages/eventos.aspx");
            }
            catch (Exception)
            {
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (Calendar1.Visible == true)
                {
                    Calendar1.Visible = false;
                    Button3.Text = "Calendario";
                }
                else
                {
                    Calendar1.Visible = true;
                    Button3.Text = "Ocultar";
                }
            }
            catch (Exception)
            {
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            try
            {
                if (Calendar2.Visible == true)
                {
                    Calendar2.Visible = false;
                    Button4.Text = "Calendario";
                }
                else
                {
                    Calendar2.Visible = true;
                    Button4.Text = "Ocultar";
                }
            }
            catch (Exception)
            {
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                HttpCookie cookie = Request.Cookies["idEvento"];
                culturaDataContext cultura = new culturaDataContext();
                if (cookie != null)
                {
                    EVENTO evento = cultura.EVENTOs.Single(ev => ev.ID_EVENTO == decimal.Parse(cookie.Value));
                    
                    evento.NOMBRE_EVENTO = this.TextBox1.Text.Trim();
                    evento.UBICACION_EVENTO = this.TextBox2.Text.Trim();
                    evento.INICIO_EVENTO = this.Calendar1.SelectedDate;
                    evento.FIN_EVENTO = this.Calendar2.SelectedDate;
                    evento.AUDIENCIA_EVENTO = int.Parse(this.TextBox5.Text.Trim());
                    evento.DESCRIPCION_EVENTO = this.TextBox6.Text.Trim();
                    
                    cultura.SubmitChanges();

                    Response.Write("<p>Cambios realizados con &eacute;xito</p>");
                    Response.Redirect("/Pages/eventos.aspx");
                }
                else
                {
                    Response.Redirect("/Pages/error.aspx");
                }
            }
            catch (Exception)
            {
            }
        }
    }
}